<?php

namespace App\Http\Requests\Admin\GameTool;

use App\Models\Enum\RedPacket;
use Illuminate\Contracts\Validation\Validator;
use Illuminate\Foundation\Http\FormRequest;
use Illuminate\Http\Exceptions\HttpResponseException;
use Illuminate\Http\JsonResponse;
use Illuminate\Validation\ValidationException;
use  Illuminate\Validation\Rule;

class RedPacketWithdrawRequest extends FormRequest
{
    /**
     * Determine if the user is authorized to make this request.
     *
     * @return bool
     */
    public function authorize()
    {
        return true;
    }

    /**
     * Get the validation rules that apply to the request.
     *
     * @return array
     */
    public function rules()
    {
        return [
            'id' => 'required|integer|exists:mysql.mc_api_redpacket,id,stat,' . RedPacket::PENDING_PAYMENT,
        ];

    }

    public function messages()
    {
        return [
            'id.required' => '请输入红包发放表id',
            'id.integer' => 'id必须为整数',
            'id.exists' => '订单已处理或不存在',
        ];
    }


    protected function prepareForValidation()
    {

    }

    protected function failedValidation(Validator $validator)
    {
        $error = $validator->errors()->all();
        $error = implode('|', $error);

        flash($error)->error()->important();
    }
}
